/*
 * Copyright (C) 2012-2013 Matthias Zeimer and the miniframes project group.
 * All rights reserved. 
 * 
 * Licensed under the Eclipse Public License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.opensource.org/licenses/EPL-1.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.miniframes.minivalues;

import static org.junit.Assert.*;

import org.junit.Test;

/**
 * <p>
 * Test-suite of {@link ValueVerifier}.
 * </p>
 * 
 * @author Matthias Zeimer
 * @version 1
 * @since 0.1, 15.06.2013
 */
public class ValueVerifierTest {

    @Test
    public void testVerifyAllRestrictions() {
        try {
            new ValueVerifier<ValueWithNonFinalField>(
                    ValueWithNonFinalField.class).verifyAllRestrictions();
            fail(InvalidValueClassDeclarationException.class.getSimpleName()
                    + " was expected.");
        } catch (InvalidValueClassDeclarationException cause) {
            // TODO: List all errors in cause?
        }
    }
}

class ValueWithNonFinalField extends DomainValue<ValueWithNonFinalField> {
    private static final long serialVersionUID = 6904363206246152537L;
    
    // HERE is the mistake (field is not final):
    private int val;

    private ValueWithNonFinalField() {
        super();
    }

    private ValueWithNonFinalField(int val) {
        super("%d", val);
        this.val = val;
    }

    public ValueWithNonFinalField valueOf(int val) {
        ValueWithNonFinalField result = new ValueWithNonFinalField(val);
        result.val = 4; // This would be possible if field is not final ->
                        // breaks unmodifiable rule.
        return result;
    }
}